package com.wkf.truck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wkf.truck.model.Address;
import com.wkf.truck.dao.AddressDao;
import com.wkf.truck.model.User;
import com.wkf.truck.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wkf.truck.service.UserService;
import com.wkf.truck.vo.AddressVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lxb
 * @since 2021-02-14
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressDao, Address> implements AddressService {

    @Resource
    private AddressDao addressDao;


    @Override
    public List<AddressVo> getAddressList(Long userId) {

        List<Address> addressList = addressDao.selectList(new QueryWrapper<Address>().eq("user_id", userId));


        List<AddressVo> list = addressList.stream().map(item -> {
            AddressVo addressVo = new AddressVo();
            BeanUtils.copyProperties(item, addressVo);
            addressVo.setAddressId(item.getId());
            return addressVo;
        }).collect(Collectors.toList());

        return list;
    }
}
